﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.BLL;
using Automobile.service.Model;
using System.Data;
namespace Automobile.service.UI
{
    public partial class CommodityEdit : System.Web.UI.Page
    {
        ProductBLL bll = new ProductBLL();
        public void LoadDite()
        {
            DataTable table = bll.Product_Hu( Convert.ToInt32(this.Product_Id.Value));
            this.Product_Name.Text = table.Rows[0][1].ToString();
            this.Product_Modelspe.Text = table.Rows[0][2].ToString();
            this.Product_Bprid.Text = table.Rows[0][3].ToString();
            this.Product_Price.Text = table.Rows[0][4].ToString();
            this.Product_Barcode.Text = table.Rows[0][5].ToString();
            this.Product_frim.Text = table.Rows[0][6].ToString();
            this.Product_Unit_Id.Text = table.Rows[0][7].ToString();
            this.Product_Remark.Text = table.Rows[0][8].ToString();
            this.Product_Type_Id.SelectedValue = table.Rows[0][9].ToString();
        }
        public void Loadxiala()
        {
            this.Product_Type_Id.DataSource = bll.Product_Type_Show();
            this.Product_Type_Id.DataValueField = "Product_Type_Id";
            this.Product_Type_Id.DataTextField = "Product_Type_Name";
            this.Product_Type_Id.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {  
               
                if (Request.QueryString["id"].ToString() != null)
                {
                    this.Product_Id.Value = Request.QueryString["id"].ToString();
                    Loadxiala();
                    LoadDite();
                }
               
                  
            }
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            Product sur = new Product();
            sur.Product_Barcode = this.Product_Barcode.Text;
            sur.Product_Bprid = Convert.ToDecimal(this.Product_Bprid.Text);
            sur.Product_frim = this.Product_frim.Text;
            sur.Product_Modelspe = this.Product_Modelspe.Text;
            sur.Product_Name = this.Product_Name.Text;
            sur.Product_Price = Convert.ToDecimal(this.Product_Price.Text);
            sur.Product_Remark = this.Product_Remark.Text;
            sur.Product_Type_Id = Convert.ToInt32(this.Product_Type_Id.SelectedValue);
            sur.Product_Unit_Id = this.Product_Unit_Id.Text;
            sur.Product_Id = Convert.ToInt32(Request.QueryString["id"]);
            if (bll.UptProduct(sur) > 0)
            {
                Response.Write("<script>alert('修改成功');parent.layer.close(parent.layer.getFrameIndex(window.name));</script>");

            }
            else
            {
                Response.Write("<script>alert('修改失败')</script>");
            }
        }
    }
}